﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <script src="~/Scripts/jquery-1.8.2.js"></script>
    <script src="~/Scripts/jquery.form.js"></script>
</head>
<body>
    <div id="excelUpdate"></div>
    <form id="fileForm" method="post" enctype="multipart/form-data">
        <input id="fileData" name="fileData" type="file" />
    </form>
    <input id="uploadType" name="uploadType" type="text" />
    <input id="fileName" name="fileName" type="text" />
    <input type="button" value="Submit" onclick="SubmitGetCouponName()" />
    <input type="button" value="DownLoad" onclick="DownLoadFile()" />
    <input id="imgurl" name="imgurl" type="text" />
    <div id="fileDown"></div>
    <script>

        function SubmitGetCouponName() {
            var getUrl = "/Home/GetCouponName";
            $.ajax({
                url: getUrl,
                dataType: "JSON",
                data: { code: $("#fileName").val() },
                success: function (data) {
                    alert(data)
                }
            });
        }

        function DownLoadFile() {
            var getUrl = "/Home/DownLoadFile";
            $('#fileForm').attr("action", getUrl).ajaxSubmit({
                beforeSubmit: function () {
                    isSubmit = true;
                },
                data: {},
                success: function (data) {
                    window.open("/Home/DownLoad?fileName=fff.xlsx&bytes=" + data);
                    //$("#fileDown").html("<iframe src=\""+data+"\"></iframe>");
                    return false;
                }
            });
        }

        var isSubmit = false;
        //提交问题
        function SubmitQuestion() {
            var getUrl = "http://jsapi.sellerinfo.ymatou.com/FileOperation/UploadFile";
            $('#fileForm').attr("action", getUrl).ajaxSubmit({
                beforeSubmit: function () {
                    isSubmit = true;
                },
                data: { uploadType: 1 },
                success: function (data) {
                    if (data != null && data.Code == 0) {
                        $("#imgurl").val(data.Result);
                    }
                    isSubmit = false;
                    $("#imgurl").val(getUrl);
                    return false;
                }
            });
        }


        function showIPTest(ip) {
            document.body.innerHTML += "<div style='background-color:#808080;font-size:20px;z-index:9999999; position:fixed;left:5px;bottom:5px; opacity:0.5;'>IP:" + ip + "</div>";
        }

        function writeLog(msg) {
            console.log(msg);
        }
        //XmlHttpRequest对象
        function createXmlHttpRequest() {
            if (window.ActiveXObject) { //如果是IE浏览器
                return new ActiveXObject("Microsoft.XMLHTTP");
            } else if (window.XMLHttpRequest) { //非IE浏览器
                return new XMLHttpRequest();
            }
        }

        var xmlHttpRequest = null;

        function getLocalIPAddr() {
            try {
                writeLog("发送请求");
                xmlHttpRequest = createXmlHttpRequest();
                //2.设置回调函数
                xmlHttpRequest.onreadystatechange = getIP;

                //3.初始化XMLHttpRequest组建
                xmlHttpRequest.open("GET", "http://myapitest.ymatou.cn/Home/GetIP?url=" + window.location.href, true);

                //4.发送请求
                xmlHttpRequest.send(null);
            } catch (e) {
                writeLog("请求错误");
            }
        }

        function getIP() {
            showIPTest(xmlHttpRequest.response);
        }

        getLocalIPAddr();
    </script>
</body>
</html>
